package main

import (
	"context"
	"google.golang.org/grpc"
	"mock/grpc_test/proto"
	"net"
	"time"
)

type Server struct {}

func (s *Server) SayHello(ctx context.Context, request *proto.HelloRequest) (*proto.HelloReply, error) {

	//return nil, status.Errorf(codes.NotFound, "字段名：%s 未找到", request.Name)
	time.Sleep(time.Second * 5)

	//业务逻辑
	return &proto.HelloReply{
		Message: "hello " + request.Name,
	}, nil
}

func main() {
	server := grpc.NewServer()
	proto.RegisterGreeterServer(server, &Server{})
	listen, err := net.Listen("tcp", "0.0.0.0:8888")
	if err != nil {
		panic("failed to listen :" + err.Error())
	}
	err = server.Serve(listen)
	if err != nil {
		panic("failed to start grpc:" + err.Error())
	}
}